/**
 * Definition for isBadVersion()
 * 
 * @param {integer} version number
 * @return {boolean} whether the version is bad
 * isBadVersion = function(version) {
 *     ...
 * };
 */

/**
 * @param {function} isBadVersion()
 * @return {function}
 */
 var totalVersion = 2; // 共有几个版本
 var wrongBadVersion = 2; // 第一个错误的版本
var solution = function() {
        var left = 1;
        var right = totalVersion;
        while(left<right) {
            var mid = parseInt((left+right)/2);
            console.log(`mid:${mid}`)
            if (isBadVersion(mid)) {
            	console.log(`当前有问题的版本是:${mid}`)
                right = mid
            } else {
                left = mid + 1
            }
        }
        return left
};

function isBadVersion(n) {
	if (n >= wrongBadVersion) {
		return true
	}
	return false
}
(function () {
	console.log(`第一个有问题的版本是${solution()}`)
})()